package com.example.armmvvm.ui.constraint.scrollfallview

import android.view.View
import android.view.ViewGroup
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.LifecycleOwner
import com.example.arm.ext.dpInt
import com.example.armmvvm.R
import com.example.armmvvm.databinding.LayoutBottomBehaviorBad2Binding
import com.example.armmvvm.ui.constraint.fragment.SideBySideNestedScrollFragment
import com.example.armmvvm.ui.fallview.FallViewMode
import com.example.armmvvm.ui.fallview.MiddleHeightCalc
import com.example.armmvvm.ui.fallview.BottomFallView
import com.example.armmvvm.ui.fallview.BottomFallViewSetting

/**
 *
 * 包名：com.example.armmvvm.ui.constraint.scrollfallview
 * 文件描述：
 * 创建人：yanghaozhang
 * 创建时间：2023/1/5 9:56
 * 修改人：
 * 修改时间：
 * 修改备注：
 * @Version:1.0
 */
class ContentScrollFallView(lifecycleOwner: LifecycleOwner, viewContainer: ViewGroup) :
    BottomFallView(lifecycleOwner, viewContainer, R.layout.layout_bottom_behavior_bad2) {
    lateinit var binding: LayoutBottomBehaviorBad2Binding

    override fun updateView(view: View) {
        binding = LayoutBottomBehaviorBad2Binding.bind(view)
        binding.apply {

            tvContent.text = "ContentScrollFallView::下层的嵌套View无法下拉"

            scrollFrameContent.updateLayoutParams {
                height = 900.dpInt
            }

            ivRightArrow.setOnClickListener {
                FrameScrollFallView(lifecycleOwner, viewContainer).show()
            }
        }
    }

    override fun afterShow(view: View) {
        super.afterShow(view)
        (lifecycleOwner as FragmentActivity).supportFragmentManager
            .beginTransaction()
            .replace(R.id.scrollFrameContent, SideBySideNestedScrollFragment(), "ContentScrollFallView")
            .commit()
    }

    override fun bottomFallViewSetting(view: View): BottomFallViewSetting? {
        return BottomFallViewSetting(view).apply {
            mode = FallViewMode.THREE_STATE
            calcHeight = {
                peekHeight = 200.dpInt
            }
            middleHeightCalc = MiddleHeightCalc.withRatioMiddleHeight(0.5f)
        }
    }
}